// steeringwheel.h
#ifndef STEERINGWHEEL_H
#define STEERINGWHEEL_H

#include <QGraphicsObject>
#include <QPropertyAnimation>

class SteeringWheel : public QGraphicsObject
{
    Q_OBJECT
    Q_PROPERTY(qreal rotation READ rotation WRITE setRotation)

public:
    explicit SteeringWheel(QGraphicsItem* parent = nullptr);

    // 必须实现的纯虚函数
    QRectF boundingRect() const override;
    void paint(QPainter* painter,
               const QStyleOptionGraphicsItem* option,
               QWidget* widget = nullptr) override;

    qreal rotation() const;
    void setRotation(qreal newRotation);
    void setRotation1(qreal newRotation);
signals:
    void rotationChanged(qreal angle);  // 角度变化信号

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;

private:
    void updateRotation(const QPointF& mousePos);
    void handleJoystickClick(const QPointF &pos);
    qreal m_rotation = 0;
    qreal m_rotation1 = 0;
    QPointF m_lastPos;
    QPointF m_center;      // 方向盘中心点
    bool m_dragging = false;
};

#endif // STEERINGWHEEL_H
